<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Exceptions\InvalidException;
use Illuminate\Support\Facades\Auth;
use App\Jobs\ApiReqJob;


class ApiBaseController extends Controller
{
   public function __construct()
   {
        //检查权限
        $this->_initialize();
    }

   public function _initialize()
   {

   }

   public function getUserId()
   {
        $id = Auth::id();
        if(!$id) {
            throw new InvalidException('请登录');
        }
        return $id;
   }
   public function sucRes($code=200,$data=[])
   {
       return json_encode([
           'code'=>$code,
           'message'=>'ok',
           'data'=>$data
       ]);
   }

   public function errRes($code=-1,$message='')
   {
       return json_encode([
           'code'=>$code,
           'message'=>$message
       ]);
   }
}
